package cn.itcast.mp.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 添加时自动填充的方法
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        Object creatDate = getFieldValByName("createDate", metaObject);
        if (null==creatDate){
            setFieldValByName("createDate", LocalDateTime.now(),metaObject);
        }

    }

    /**
     * 修改时的自动填充
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {

    }
}
